<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
    <!-- filter 条件查询 -->
    <div class="btn-add">
        <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="addInOrOut"
        >
            新增</el-button
        >
    </div>

    <!-- 新增数据弹窗 -->
    <el-dialog
      :title="title"
      :visible.sync="showAdd"
      @close="closeShow"
      width="60%"
    >
        <el-form :model="createForm" ref="createForm" :rules="addRules">
            <el-row :gutter="0">    
            <el-col :span="6">
              <el-form-item label="工作中心" prop="workCenter" label-width="80px" >
                <el-select
                    v-model="createForm.workCenter"
                    @focus="getCenterList" 
                    @change="getProcess"
                    placeholder="请选择工作中心"
                    class="ul-item"
                    filterable
                    clearable>
                    <el-option
                        v-for="(item,index) in this.centerList"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="岗位类别" prop="jobCategory"  label-width="80px">
                <el-select
                    v-model="createForm.jobCategory"
                    placeholder="请选择岗位类别"
                    @change="jobCategoryC"
                    class="ul-item"
                    filterable
                    clearable>
                    <el-option
                        v-for="(item,index) in this.jobCategoryList"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="岗位名称" prop="jobTitle"  label-width="80px" >
                  <el-input placeholder="请输入岗位名称" clearable v-model.trim="createForm.jobTitle" class="ul-item"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="岗位级别" prop="rankOfPosition"  label-width="80px">
                <el-select
                    v-model="createForm.rankOfPosition"
                    placeholder="请选择岗位级别"
                    filterable
                    clearable
                    class="ul-item">
                    <el-option
                        v-for="(item,index) in this.rankOfPositionList"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
              </el-form-item>
            </el-col>
           </el-row>
            <el-row :gutter="0">
              <!-- <el-col :span="6">
                <el-form-item label="关键岗位" prop="keyPosition" label-width="80px" >    
                    {{ '否 ' }}<el-switch  v-model="createForm.keyPosition" active-value="1" inactive-value="0" />{{ ' 是' }}
              </el-form-item>
              </el-col> -->
              <el-col :span="6">    
                 <el-form-item label="上岗方式" prop="entryMode" >
                    <el-select
                    v-model="createForm.entryMode"
                    placeholder="请选择上岗方式"
                    filterable
                    clearable
                    class="ul-item"  style="width: 220px">
                       <el-option  v-for="(item,index) in this.wayList" :key="index"  :label="item" :value="item" />
                    </el-select>
                 </el-form-item>
              </el-col>
              <el-col :span="18" v-if="createForm.jobCategory !== '2线'">
                 <el-form-item label="可工作工序" prop="permissibleOperation" >
                    <el-checkbox-group v-model="createForm.permissibleOperation">
                      <el-checkbox v-for="item in processList" :label="item" :key="item">{{item}}</el-checkbox>
                    </el-checkbox-group>
                     <!-- <el-cascader  style="width: 400px" @change="change11" @focus="getProcess" :props="props" v-model="createForm.permissibleOperation" :options="processList" clearable class="ul-item"/> -->
                   <!-- <el-input @focus="process" v-model="createForm.permissibleOperation" autosize style="width: 150px"/> -->
                 </el-form-item>
              </el-col>
            </el-row>
            <el-link type="primary" style="margin: 0 0 0 30px;">岗位晋级标准</el-link>
            <el-form-item label="本岗位工作时长≥" prop="bePromotedEntryTimeStandard" label-width="150px">
                    <el-select
                    v-model="createForm.bePromotedEntryTimeStandard"
                    placeholder="请选择自动晋级月份"
                    filterable
                    clearable
                    class="ul-item"  style="width: 200px">
                       <el-option v-for="(item,index) in this.entryTimeList" :key="index"  :label="item.name" :value="item.id" />
                    </el-select>{{' 入职时间大于等于设定值为自动晋级条件之一'}}
            </el-form-item>
            <el-form-item label="工作质量系数平均≥" prop="bePromotedWorkingQualityFactor" label-width="150px">
                
                <el-input v-model.number="createForm.bePromotedWorkingQualityFactor" type="number" autosize style="width: 200px"/>{{' 本岗位工作时长的平均值'}}
            </el-form-item>
            <el-form-item label="缺勤≤" prop="bePromotedAbsenceFromDuty" label-width="150px">
                <el-input v-model.number="createForm.bePromotedAbsenceFromDuty" type="number" autosize style="width: 200px"/>{{ ' 本岗位工作时长内缺勤小于等于设定值为岗位晋级标准条件之一/台数达到为晋级条件之一' }}
            </el-form-item>
            <el-form-item label="关键事件≤" prop="bePromotedPointsAreDeductedForCriticalMatters" label-width="150px">
                <el-input v-model="createForm.bePromotedPointsAreDeductedForCriticalMatters" type="number" autosize style="width: 200px"/>{{ ' 本岗位工作时长内关键时间小于等于设定值为岗位晋级标准条件之一' }}
            </el-form-item>
            <el-form-item label="生产效率≥" prop="bePromotedCumulativeOutputStandard" label-width="150px">
                <el-input v-model="createForm.bePromotedCumulativeOutputStandard" autosize style="width: 200px"/>
            </el-form-item>
            <el-link type="primary" style="margin: 0 0 0 30px;">岗位降级标准</el-link>
            <el-form-item label="平均月份≥" prop="demotionAverageMonth" label-width="150px">
                    <el-select
                    v-model="createForm.demotionAverageMonth"
                    placeholder=""
                    filterable
                    clearable
                    class="ul-item"  style="width: 200px">
                       <el-option  v-for="(item,index) in this.entryTimeList" :key="index"  :label="item.name" :value="item.id" />
                    </el-select>
            </el-form-item>
            <el-form-item label="平均品质系数≤" prop="demotionVerAgeQualityCoefficient" label-width="150px">
                    <el-input v-model.number="createForm.demotionVerAgeQualityCoefficient" type="number" autosize style="width: 200px"/>
            </el-form-item>
            <el-form-item label="关键事件扣分≥" prop="demotionPointsAreDeductedForCriticalMatters" label-width="150px">
                <el-input v-model.number="createForm.demotionPointsAreDeductedForCriticalMatters" type="number" autosize style="width: 200px"/>
            </el-form-item>
            <el-form-item label="生产效率≤" prop="demotionCumulativeOutputStandard" label-width="150px">
                <el-input v-model="createForm.demotionCumulativeOutputStandard" autosize style="width: 200px"/>
            </el-form-item>
            <el-form-item label="质量系数预警标准 ≤" prop="qualityCoefficientReminderStandard" label-width="150px">
                <el-input v-model="createForm.qualityCoefficientReminderStandard" type="number" autosize style="width: 200px"/>{{ '当月质量系数小于等于设定值时邮件提醒对应人员直接主管' }}
            </el-form-item>
            <el-form-item label="质量系数培训标准 ≤" prop="qualityFactorLayoffStandard" label-width="150px">
                <el-input v-model="createForm.qualityFactorLayoffStandard" type="number" autosize style="width: 200px"/>{{ '当月质量系数小于等于设定值时进行下岗培训' }}
            </el-form-item>
            <el-form-item label="定期培训频率" prop="frequencyOfRegularTraining" label-width="150px">
                    <el-popover v-model="cronmaintenance">
                        <cron @change="changemaintenance($event)" @close="cronmaintenance=false" i18n="cn"></cron>
                        <el-input clearable style="width: 200px;margin: 0 3px 0 6px;" slot="reference" @click="cronmaintenance=true" v-model="createForm.frequencyOfRegularTraining" placeholder="请输入定时策略"></el-input>
                    </el-popover>{{ '达到设定频率后系统启动定期培训' }}
            </el-form-item>
        </el-form>

        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showAdd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="addfacility('createForm')"
            :loading="loadBool"
            >确认</el-button
            >
        </div>
    </el-dialog>

        

    <div class="filter-container">
      <!-- style="width: 150px;margin-right:15px;" -->
        <el-select 
             v-model="param.workCenter" 
             clearable
             filterable
             style="margin-right: 15px;width: 150px"
             @focus="getCenterList" 
             placeholder="请选择工作中心"
             class="ul-item">
             <el-option :value="item" :label="item" v-for="(item,index) in this.centerList" :key="index"/>
        </el-select>
        <el-select 
             v-model="param.jobCategory" 
             clearable      
             filterable
             style="margin-right: 15px;width: 150px"
             placeholder="请选择岗位类别"
             class="ul-item">
             <el-option :value="item" :label="item" v-for="(item,index) in this.jobCategoryList" :key="index"/>
        </el-select>
        <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 15px;width: 150px"
            v-model="param.jobTitle"
            placeholder="请输入岗位名称"        
        ></el-input>

        <el-select 
             v-model="param.rankOfPosition" 
             clearable      
             filterable
             style="margin-right: 15px;width: 150px"
             placeholder="请选择岗位级别"
             class="ul-item">
             <el-option :value="item" :label="item" v-for="(item,index) in this.rankOfPositionList" :key="index"/>
        </el-select>

        <el-button type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button
            type="button"
            v-waves
            class="el-button el-button--warning"
            @click="cancelSubmit"
        >
        重置</el-button>

    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="工作中心"  prop="workCenter" align="center"/>
      <el-table-column label="岗位类别"  prop="jobCategory" align="center"/>
      <el-table-column label="岗位名称"  prop="jobTitle" align="center"/>
      <el-table-column label="岗位级别"  prop="rankOfPosition" align="center">
        <template slot-scope="scope" >
            {{ scope.row.rankOfPosition == 1 ? '试用级' 
            :scope.row.rankOfPosition == 2 ? '初级'
            :scope.row.rankOfPosition == 3 ? '中级'
            :scope.row.rankOfPosition == 4 ? '高级'
            :scope.row.rankOfPosition == 5 ? '师傅级':'-' }}
        </template>
      </el-table-column>
      <el-table-column label="上岗方式"  prop="entryMode" align="center"/>
      <el-table-column label="允许作业工序"  prop="permissibleOperation1" align="center"/>
      <el-table-column label="岗位晋级标准" align="center">
        <el-table-column label="本岗位工作时长(≥月)"  prop="bePromotedEntryTimeStandard" align="center"/>
        <el-table-column label="工作质量系数平均(本岗位工作时长)"  prop="bePromotedWorkingQualityFactor " align="center"/>
        <el-table-column label="缺勤≤"  prop="bePromotedAbsenceFromDuty" align="center"/>
        <el-table-column label="关键事项扣分≤"  prop="bePromotedPointsAreDeductedForCriticalMatters" align="center"/>
        <el-table-column label="生产效率(预留)"  prop="bePromotedCumulativeOutputStandard" align="center"/>
      </el-table-column>
      <el-table-column label="岗位降级标准" align="center">
        <el-table-column label="平均月份"  prop="demotionAverageMonth" align="center"/>
        <el-table-column label="平均品质系数≤"  prop="demotionVerAgeQualityCoefficient" align="center"/>
        <el-table-column label="关键事件扣分≥"  prop="demotionPointsAreDeductedForCriticalMatters" align="center"/>
        <el-table-column label="生产效率(预留)"  prop="demotionCumulativeOutputStandard" align="center"/>
      </el-table-column>
      <el-table-column label="定期培训频次"  prop="frequencyOfRegularTraining" align="center"/>
      <el-table-column label="当月质量系数提醒标准≤"  prop="qualityCoefficientReminderStandard" align="center"/>
      <el-table-column label="当月质量系数下岗培训标准≤"  prop="qualityFactorLayoffStandard" align="center"/>
      <el-table-column label="修改人员"  prop="updateJobNumber" align="center"/>
      <el-table-column label="修改时间"  prop="updateTime" align="center"/>
      <el-table-column label="操作" fixed="right" align="center" width="130">
            <template slot-scope="scope" >
                <div class="fx" style="display: flex">
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="handleDelete(scope.row,scope.$index)"
                    ></el-button>
                </div>
            </template>
      </el-table-column>
    </el-table>

   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-divider></el-divider>

    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>

  </div>
</template>

<script>
import { getNextExecTime } from "@/api/processRoute"
import { knowledgeFind, knowledgeSave,findProcessGroup,knowledgeUpd,knowledgeDel } from "@/api/knowledgeSkill"
import mixin from '../../utils/mixin.js'
import { cron } from 'vue-cron'
export default {
    name: 'postMaintenance',
    template: '<cron/>',
    components: { cron },
    mixins: [mixin],
    data () {
        return {
            listQuery: {
                page: 1,                                    //页码
                limit: 10                                   //每页多少条记录
            },
            param: {                 
            },
            title: '新增',
            total: 0,                                      //数据的总数
            tableInfo: [],
            loadingList: false,
            loading: false,
            createForm: {
                permissibleOperation:[]
            },
            loadBool:false,
            cronmaintenance: false,
            updForm: {},        
            props: { multiple: true, checkStrictly: true },
            // 表单校验
            addRules: {
                workCenter: [       
                    { required: true, message: "工作中心不能为空!", trigger: "change" },
                ],
                jobCategory: [
                    { required: true, message: "岗位类别不能为空!", trigger: "change" },
                ],
                jobTitle: [
                    { required: true, message: "岗位名称不能为空!", trigger: "change" },
                ],
                rankOfPosition: [
                    { required: true, message: "岗位级别不能为空!", trigger: "change" },
                ],
                keyPosition: [
                    { required: true, message: "关键岗位不能为空!", trigger: "change" },
                ],
                entryMode: [
                    { required: true, message: "上岗方式不能为空!", trigger: "change" },
                ],
                permissibleOperation: [
                    { required: true, message: "请选择可作业工序!", trigger: "change" },
                ],
                entryTimeStandard: [
                    { required: true, message: "入职时间标准不能为空!", trigger: "change" },
                ],
                workingQualityFactor: [
                    { required: true, message: "工作质量系数不能为空!", trigger: "change" },
                ],
                cumulativeOutputStandard: [
                    { required: true, message: "积累产量标准不能为空!", trigger: "change" },
                    { validator: this.validateNumber, trigger: 'change' }  
                ],
            },
            showAdd: false,
            showupd: false,
            userInfo: this.$store.state.user.userInfo,
            jobCategoryList: ['1线','1.5线','2线'],
            rankOfPositionList: ['试用级','初级','中级','高级','师傅级'],
            keyPositionList: ['是','否'], 
            wayList: ['可独立上岗','初级以上员工一同绑定','中级以上员工一同绑定','高级以上员工一同绑定  ','师傅级以上员工一同绑定'],
            // entryTimeList: ['新入职','1个月','3个月','6个月','9个月','12个月','15个月','18个月','24个月'],   
            entryTimeList:[
              {
                name: '新入职',
                id: 0
              },
              {
                name: '1个月',
                id: 1
              },
              {
                name: '3个月',
                id: 3
              },
              {
                name: '6个月',
                id: 6
              },
              {
                name: '9个月',
                id: 9
              },
              {
                name: '12个月',
                id: 12
              },
              {
                name: '15个月',
                id: 15
              },
              {
                name: '18个月',
                id: 18
              },
              {
                name: '24个月',
                id: 24
              },
            ],
            dutyFactor: [
              {
                name:'每3个月培训1次',
                id:3,
              },
              {
                name:'每6个月培训1次',
                id:6,
              },
              {
                name:'每12个月培训1次',
                id:12,
              },
              {
                name:'每18个月培训1次',
                id:18,
              },
              {
                name:'每24个月培训1次',
                id:24,
              }
            ],
        }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    methods: {
        changemaintenance(val){
          let arr = val.split(" ");
          arr.pop()
          this.createForm.frequencyOfRegularTraining=arr.join(" ")
          this.reminder5(this.createForm.frequencyOfRegularTraining)
        },
        // 进5次的提醒
        async reminder5(e){
        let query = {
          numTimes: 5,
          cronExpression: e
        }
        const res = await getNextExecTime(query)
         let messageContent = ''
        res.data.forEach(item => {  
        // 将每个项目添加到 messageContent 字符串中，并在每个项目后添加换行符  
        messageContent += `<div>${item}</div>`;  
      });
      // 去除字符串末尾的换行符（如果有的话）  
      if (messageContent.endsWith('\n')) {      
        messageContent = messageContent.slice(0, -1);  
      }  
        this.$message({     
          dangerouslyUseHTMLString: true,
          message: `<div>近五次的执行结果:</div>${messageContent}`,
          type: 'success',
          duration: 5000
        });
    },
        getData(){
          this.listQuery.page = 1
          this.listQuery.limit = 10
          this.handleFilter()
        },
        getChange(){
            this.createForm.permissibleOperation = []
        },
        // 自定义校验规则  
        validateNumber(rule, value, callback) {     
          if (!value) {  
            return callback(new Error('请输入数字'));  
          }  
          // 使用正则表达式校验是否只包含0-9的数字  
          const reg = /^[0-9]*$/;  
          if (!reg.test(value)) {  
            callback(new Error('只能输入0-9的数字'));  
          } else {  
            callback();  
          }  
        },
        // 工作岗位改变
        jobCategoryC(e){
            if(e == '2线'){
                this.createForm.permissibleOperation = []
            }
        },
        closeShow(){
            if(this.title == '修改'){       
                this.createForm = {
                permissibleOperation:[]
              }
              this.processList = []
            this.$refs.createForm.resetFields()
            }
            this.showAdd = false
        },
        // 获取工序
        async getProcess(){
          this.createForm.permissibleOperation = []
          let query ={workCenter:this.createForm.workCenter}
          this.processList = []
          let {data} = await findProcessGroup(query)
          console.log('data',data);
          if(!data.length) return this.$message.error('该工作中心没有工序！')
          data.forEach(item=>{
            this.processList.push(item.processNameGz)
        })
        console.log(11,this.processList)
        },
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery)
            if(this.param.workCenter){ query.workCenter = this.param.workCenter}
            if(this.param.jobCategory){ query.jobCategory = this.param.jobCategory}
            if(this.param.jobTitle){ query.jobTitle = this.param.jobTitle}
            if(this.param.keyPosition == '是'){query.keyPosition = 1} else if(this.param.keyPosition == '否'){query.keyPosition = 0}
            console.log(this.param.rankOfPosition)
            if(this.param.rankOfPosition){  
                this.param.rankOfPosition == '试用级' ? query.rankOfPosition = 1
                :this.param.rankOfPosition == '初级' ? query.rankOfPosition = 2
                :this.param.rankOfPosition == '中级' ? query.rankOfPosition = 3
                :this.param.rankOfPosition == '高级' ? query.rankOfPosition = 4
                :this.param.rankOfPosition == '师傅级' ? query.rankOfPosition = 5:''
            }
            console.log(query)
            let data = await knowledgeFind(query)
            let errmsg = data.msg
            this.loadingList = false
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            this.total = data.data.count
            this.tableInfo = data.data.list
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
          this.listQuery.limit = val
          this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
          this.listQuery.page = val
          this.handleFilter()
        },
        transformDat(res) {
          const mapInfo = {
            index: '序号',
            workCenter: '工作中心',
            jobCategory: '岗位类别',
            jobTitle: '岗位名称',
            keyPosition: '关键岗位',
            rankOfPosition: '岗位级别',
            entryMode: '上岗方式',
            permissibleOperation1: '允许作业工序',
            bePromotedEntryTimeStandard: '本岗位工作时长(≥月)',
            bePromotedWorkingQualityFactor: '工作质量系数平均(本岗位工作时长)',
            bePromotedAbsenceFromDuty: '缺勤≤',
            bePromotedPointsAreDeductedForCriticalMatters: '关键事项扣分≤',
            bePromotedCumulativeOutputStandard: '生产效率(预留)',
            demotionAverageMonth: '平均月份',
            demotionVerAgeQualityCoefficient: '平均品质系数≤',
            demotionPointsAreDeductedForCriticalMatters: '关键事件扣分≥',
            demotionCumulativeOutputStandard: '生产效率(预留)',
            frequencyOfRegularTraining: '定期培训频次',
            qualityCoefficientReminderStandard: '当月质量系数提醒标准≤',
            qualityFactorLayoffStandard: '当月质量系数下岗培训标准≤',
            updateJobNumber: '修改人员',
            updateTime: '修改时间',
          }
          // 对data进行格式化
          // 取出所有的属性名
          const props = Object.keys(res[0]) // ['id','']    
          // 将属性名从英文转为中文
          const header = props.map(zhkey => mapInfo[zhkey])
          console.log('中文的表头', header)
          // const data=[['xxxx','总裁办'，'13800000']]
          const data = res.map(obj => Object.values(obj))
          return { header, data }
        },
        handleDelete(row,index) {
            this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.delprocess(row,index)
            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
            })
        },
        async delprocess(row,index){
          let res = await knowledgeDel({id: row.id,jobCategory:row.jobCategory})
          if(res.code == '500') return
          if(res.code != '1') return this.$message.error(res.msg)
          this.tableInfo.splice(index,1)
          this.$message.success(res.msg)
        },
        // 导出excel
        async hExportExcel() {
          this.loading = true
          let query = Object.assign({},this.listQuery)
          query.page = 1
          query.limit = 10000
          if(this.param.workCenter){ query.workCenter = this.param.workCenter}
          if(this.param.jobCategory){ query.jobCategory = this.param.jobCategory}
          if(this.param.jobTitle){ query.jobTitle = this.param.jobTitle}
          if(this.param.rankOfPosition){ query.rankOfPosition = this.param.rankOfPosition}
          if(this.param.keyPosition == '是'){query.keyPosition = 1} else if(this.param.keyPosition == '否'){query.keyPosition = 0}
          let arr = await knowledgeFind(query)
          if(arr.code == '500') return
          if(arr.code != '1'){
            this.loading = false
            return this.$message.error(errmsg)
          }
          if(!arr.data.list.length){
            this.loading = false
            this.$message.error('暂无数据')
          }
          const { header, data } = this.transformDat(this.setSort(arr.data.list))
          import('@/vendor/Export2Excel').then(excel => {
            // excel表示导入的模块对象
            console.log(excel)
            excel.export_json_to_excel({
            header, // 表头 必填
            data, // 具体数据 必填
            filename: '岗位维护列表', // 文件名称
            autoWidth: true, // 宽度是否自适应
            bookType: 'xlsx' // 生成的文件类型
            })
          })
          this.loading = false
        },
        // 排序函数
        setSort(arr){
          let newArr = JSON.parse(JSON.stringify(arr))
          let arr1 = []
          newArr.forEach((item,index)=>{
            let obj = {
                index: item.index,
                workCenter: item.workCenter,
                jobCategory: item.jobCategory,
                jobTitle: item.jobTitle,
                keyPosition: item.keyPosition == 1 ? '是':'否',
                rankOfPosition: item.rankOfPosition == 1 ? '试用级' : item.rankOfPosition == 2 ? '初级' : item.rankOfPosition == 3 ? '中级' : item.rankOfPosition == 4 ? '高级' : item.rankOfPosition == 5 ? '师傅级':'-',
                entryMode: item.entryMode,
                permissibleOperation1: item.permissibleOperation1,
                bePromotedEntryTimeStandard: item.bePromotedEntryTimeStandard,
                bePromotedWorkingQualityFactor: item.bePromotedWorkingQualityFactor,
                bePromotedAbsenceFromDuty: item.bePromotedAbsenceFromDuty,
                bePromotedPointsAreDeductedForCriticalMatters: item.bePromotedPointsAreDeductedForCriticalMatters,
                bePromotedCumulativeOutputStandard: item.bePromotedCumulativeOutputStandard,
                demotionAverageMonth: item.demotionAverageMonth,
                demotionVerAgeQualityCoefficient: item.demotionVerAgeQualityCoefficient,
                demotionPointsAreDeductedForCriticalMatters: item.demotionPointsAreDeductedForCriticalMatters,
                demotionCumulativeOutputStandard: item.demotionCumulativeOutputStandard,
                frequencyOfRegularTraining: item.frequencyOfRegularTraining,
                qualityCoefficientReminderStandard: item.qualityCoefficientReminderStandard,
                qualityFactorLayoffStandard: item.qualityFactorLayoffStandard,
                updateJobNumber: item.updateJobNumber,
                updateTime: item.updateTime,
            }
            arr1.push(obj)
          })
          return arr1
        },
        cancelSubmit(){
            this.param = {}
            this.listQuery.page = 1
            this.handleFilter()
        },
        // 提交表单之前先进行验证
        addfacility(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submitprocess()
                } else {
                    return false
                }
            })
        },
        async submitprocess(){
            let query = Object.assign({},this.createForm)
            // if(this.createForm.keyPosition == '是'){query.keyPosition = 1} else{query.keyPosition = 0}
            if(this.createForm.permissibleOperation.length){
                query.permissibleOperation = this.createForm.permissibleOperation.join()
            } else{ 
                query.permissibleOperation = null
            }
            if(this.createForm.rankOfPosition){     
                this.createForm.rankOfPosition == '试用级' ? query.rankOfPosition = 1
                :this.createForm.rankOfPosition == '初级' ? query.rankOfPosition = 2
                :this.createForm.rankOfPosition == '中级' ? query.rankOfPosition = 3
                :this.createForm.rankOfPosition == '高级' ? query.rankOfPosition = 4
                :this.createForm.rankOfPosition == '师傅级' ? query.rankOfPosition = 5:''
            }
            console.log('query', query)
            let data
            this.loadBool = true
            console.log(this.loadBool)
            if(this.title == '新增'){
                data = await knowledgeSave(query)
            } else{
                data = await knowledgeUpd(query)
            }
            const errMsg = data.msg
            this.loadBool = false
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.$message.success(errMsg)
            this.resetForm()
            this.showAdd = false
            this.handleFilter()
        },
        resetForm(){
            this.createForm = {
                permissibleOperation:[]
              }
              this.processList = []
             this.$refs.createForm.resetFields();
        },
        async handleEdit(row){
            this.title = '修改'
            this.createForm = Object.assign({},row)
            this.createForm.rankOfPosition == 1 ? this.createForm.rankOfPosition = '试用级' 
                :this.createForm.rankOfPosition == 2 ? this.createForm.rankOfPosition = '初级'
                :this.createForm.rankOfPosition == 3 ? this.createForm.rankOfPosition = '中级'
                :this.createForm.rankOfPosition == 4 ? this.createForm.rankOfPosition = '高级'
                :this.createForm.rankOfPosition == 4 ? this.createForm.rankOfPosition = '师傅级':''
            let query ={workCenter:this.createForm.workCenter}
              this.processList = []
              let {data} = await findProcessGroup(query)
              let arr = data
              arr.forEach(item=>{
                if(item){
                    this.processList.push(item.processNameGz)
                }   
            })
            if(row.permissibleOperation1){
                this.createForm.permissibleOperation = row.permissibleOperation1.split(",")
                console.log(this.createForm.permissibleOperation)
            }else{
                this.createForm.permissibleOperation = []
            }
            delete this.createForm.permissibleOperation1
            console.log(this.createForm)
            this.showAdd = true
        },
        addInOrOut(){
            this.title = '新增'
            console.log(this.createForm)
            this.showAdd = true
        },
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
    }
}
</script>

<style>

.btn-add{
    margin-bottom: 28px;
}

.ul-item{
  width: 85%;
}
</style>
